package com.ruoyi.base.controller;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ruoyi.base.domain.SProjectFee;
import com.ruoyi.base.service.ISProjectFeeService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.domain.entity.SysDictData;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.StringUtils;
import com.ruoyi.options.domain.Option;
import com.ruoyi.system.service.ISysDictDataService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

@RestController
@RequestMapping("/base/project-fee")
public class SProjectFeeController extends BaseController {

    @Autowired
    ISProjectFeeService projectService;

    @GetMapping("/list")
    public TableDataInfo list(SProjectFee project){
        startPage();
        QueryWrapper<SProjectFee> queryWrapper = new QueryWrapper<>();

        queryWrapper.lambda()
                .eq(StringUtils.isNotEmpty(project.getFeeType()), SProjectFee::getFeeType, project.getFeeType())
                .like(StringUtils.isNotEmpty(project.getProjectFeeName()), SProjectFee::getProjectFeeName, project.getProjectFeeName())
                .eq(StringUtils.isNotEmpty(project.getCompanyCod()), SProjectFee::getCompanyCod, project.getCompanyCod())
                .eq(StringUtils.isNotEmpty(project.getProjectType()), SProjectFee::getProjectType, project.getProjectType())
                .orderByAsc(SProjectFee::getCompanyCod)
                .orderByDesc(SProjectFee::getCreateTime);

        List<SProjectFee> projectList = projectService.list(queryWrapper);

        return getDataTable(projectList);
    }

    @GetMapping("/getOne/{id}")
    public AjaxResult getOne(@PathVariable Long id){

        return AjaxResult.success(projectService.getById(id));

    }

    @GetMapping("/label")
    public AjaxResult label(SProjectFee project){
        return projectService.label(project);
    }

    @GetMapping("/option")
    public AjaxResult option(SProjectFee project){
        return projectService.option(project);
    }

    @PostMapping("/add")
    @PreAuthorize("@ss.hasPermi('base:project:add')")
    @Log(title = "新增服务", businessType = BusinessType.INSERT)
    public AjaxResult add(@RequestBody SProjectFee project){

        return projectService.insert(project);

    }

    @PutMapping("/edit")
    @PreAuthorize("@ss.hasPermi('base:project:edit')")
    @Log(title = "修改服务", businessType = BusinessType.UPDATE)
    public AjaxResult edit(@RequestBody SProjectFee project){

        return projectService.update(project);

    }

    @DeleteMapping("/remove/{ids}")
    @PreAuthorize("@ss.hasPermi('base:project:remove')")
    @Log(title = "删除服务", businessType = BusinessType.DELETE)
    public AjaxResult remove(@PathVariable Long[] ids){

        return toAjax(projectService.removeByIds(Arrays.asList(ids)));

    }

}
